//
//  NoticeVC.m
//  ProjectSource_Demo
//
//  Created by Liu on 16/3/24.
//  Copyright © 2016年 AngryBear. All rights reserved.
//

#import "NoticeVC.h"

#import "SettingCell.h"

@interface NoticeVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation NoticeVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexRGB:0xefefef];
    self.title = @"消息通知";
    [self.view addSubview:self.tableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SettingCell class])];
    cell.titleLabel.hidden = NO;
    
    if (indexPath.section == 0) {
        cell.rightLabel.hidden = NO;
        cell.titleLabel.text = @"接受新消息通知";
        cell.rightLabel.text = @"已开启";
        cell.bottomLine.hidden = YES;
    }
    else {
        cell.switchView.hidden = NO;
        switch (indexPath.row) {
            case 0:
            {
                cell.titleLabel.text = @"订阅内容通知";
            }
                break;
            case 1:
            {
                cell.titleLabel.text = @"新的工作通知";
            }
                break;
            case 2:
            {
                cell.titleLabel.text = @"声音通知";
            }
                break;
            case 3:
            {
                cell.titleLabel.text = @"震动通知";
                cell.bottomLine.hidden = YES;
            }
                break;
                
            default:
                break;
        }
    }
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor clearColor];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(14, 15/2, self.tableView.width - 14*2, 30)];
        label.numberOfLines = 0;
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithHexRGB:0x606060];
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = NSTextAlignmentLeft;
        label.text = @"如果你要关闭或者开启新消息通知请在Iphone的\"设置\"-\"通知\"功能中，找到应用程序\"小智\"更改。";
        [view addSubview:label];
        return view;
    }
    return nil;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 45;
    }
    return 47;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }
    return 45;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - Getter Methods
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.bounces = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 15)];
        
        [_tableView registerClass:[SettingCell class] forCellReuseIdentifier:NSStringFromClass([SettingCell class])];
    }
    return _tableView;
}

@end
